package com.iflytek.autofly.navisetting;

import android.content.Context;

import com.iflytek.autofly.utils.FlyLog;

/**
 * <b>Description: </b>TODO<br/>
 * <b>Change History:</b><br/>
 * <table border="1">
 * <tr>
 * <td><b>user</b></td>
 * <td><b>date</b></td>
 * <td><b>time</b></td>
 * <td><b>reason</b></td>
 * </tr>
 * <tr>
 * <td>JunLuan@iflytek.com</td>
 * <td>2015/11/26</td>
 * <td>9:09</td>
 * <td>创建此文件</td>
 * </tr>
 * </table>
 *
 * @author JunLuan@iflytek.com
 */
public class NaviSetting {


    private static final String TAG = "NaviSetting";
    private static NaviSetting instance;
    private INaviSetting mSetting = null;

    public static NaviSetting registerListener(Context c, Object l) {
        if (instance == null) {
            instance = new NaviSetting();
        }

        instance.init(c, l);
        return instance;
    }

    public static void unregisterListener(Context applicationContext, Object l) {
        instance.fini(applicationContext);
    }

    private void init(Context c, Object l) {
        mSetting = MxNaviSetting.registerListener(c, l);
        mSetting.init(c);
    }

    private void fini(Context c) {
    }

    public void destoryClient(Context c) {
        if (mSetting != null) {
            mSetting.fini(c);
        }
    }

    public boolean getContentPlayState() {
        if (mSetting != null) {
            return mSetting.getContentPlayState();
        }
        return false;
    }

    public void setContentPlayState(boolean play) {
        if (mSetting != null) {
            mSetting.setContentPlayState(play);
        }
    }

    public PlayedContentLevel getPlayedContentLevel() {
        if (mSetting != null) {
            return mSetting.getPlayedContentLevel();
        }
        return PlayedContentLevel.STANDARD;
    }

    public void setPlayedContentLevel(PlayedContentLevel lvl) {
        if (mSetting != null) {
            mSetting.setPlayedContentLevel(lvl);
        }
    }

    public DayNightMode getDayNightMode() {
        FlyLog.d(TAG, "enter");
        if (mSetting != null) {
            return mSetting.getDayNightMode();
        }
        FlyLog.e(TAG, "setting is null");
        return DayNightMode.AUTO;
    }

    public void setDayNightMode(DayNightMode mode) {
        if (mSetting != null) {
            mSetting.setDayNightMode(mode);
        }
    }

    public NaviPathMode getNaviPathMode() {
        if (mSetting != null) {
            return mSetting.getNaviPathMode();
        }
        return NaviPathMode.SUGGEST;
    }

    public void setNaviPathMode(NaviPathMode mode) {
        if (mSetting != null) {
            mSetting.setNaviPathMode(mode);
        }
    }

    public int getSpeaker() {
        if (mSetting != null) {
            return mSetting.getSpeaker();
        }
        return 99;
    }

    public void setSpeaker(int id) {
        if (mSetting != null) {
            mSetting.setSpeaker(id);
        }
    }

    public String getNaviVersion() {
        if (mSetting != null) {
            return mSetting.getNaviVersion();
        }
        return "unknown";
    }

    public String getNaviDataVersion() {
        if (mSetting != null) {
            return mSetting.getNaviDataVersion();
        }
        return "unknown";
    }

    public enum AidlStatus {
        SERVICE_AIDL_NOT_BOUND,
        SERVICE_AIDL_BINDING,
        SERVICE_AIDL_BOUND;

        @Override
        public String toString() {
            switch (this) {
                case SERVICE_AIDL_NOT_BOUND:
                    return "SERVICE_AIDL_NOT_BOUND";
                case SERVICE_AIDL_BINDING:
                    return "SERVICE_AIDL_BINDING";
                case SERVICE_AIDL_BOUND:
                    return "SERVICE_AIDL_BOUND";
            }
            return "INVALID";
        }
    }

    public enum PlayedContentLevel {
        SIMPLE, STANDARD, FULL;

        @Override
        public String toString() {
            switch (this) {
                case SIMPLE:
                    return "SIMPLE";
                case STANDARD:
                    return "STANDARD";
                case FULL:
                    return "FULL";
            }
            return "INVALID";
        }
    }

    public enum DayNightMode {
        AUTO, DAY, NIGHT;

        @Override
        public String toString() {
            switch (this) {
                case DAY:
                    return "DAY";
                case NIGHT:
                    return "NIGHT";
                case AUTO:
                    return "AUTO";
            }
            return "INVALID";
        }
    }

    public enum NaviPathMode {
        SUGGEST, HIGHWAY, DISTANCE, ECONOMIC;

        @Override
        public String toString() {
            switch (this) {
                case SUGGEST:
                    return "SUGGEST";
                case HIGHWAY:
                    return "HIGHWAY";
                case DISTANCE:
                    return "DISTANCE";
                case ECONOMIC:
                    return "ECONOMIC";
            }
            return "INVALID";
        }
    }

    public interface IBindListener {
        void onServiceStatusChanged(AidlStatus status);
    }

    public static final class ErrorCode {
        public static final int ERROR_OK = 0;
        public static final int ERROR_PARAM_OUTOFBOUND = -1001;
        public static final int ERROR_PARAM_NULL = -1002;
        public static final int ERROR_COMMON = -1003;
        public static final int ERROR_AIDL_BINDING = -1004;
        public static final int ERROR_AIDL_NOT_BOUND = -1005;
        public static final int ERROR_AIDL_NO_SERVICE = -1006;
        public static final int ERROR_REBUNDANCE_LISTENER = -1007;
        public static final int ERROR_PLATFORM_OBJ_NULL = -1016;
        public static final int ERROR_NOT_SUPPORT = -1014;

        public ErrorCode() {
        }
    }
}
